import java.io.*;

/**
 * 使用转换流进行编码转换
 * Created by ruwenbo on 2018/6/18.
 */
public class TestStreamReader {

    public static void main(String[] args) throws IOException {

        File file = new File("E:\\", "d.txt");
        if (!file.exists()) {
            file.createNewFile();
        }
        OutputStreamWriter writer = new OutputStreamWriter(new FileOutputStream(file), "GBK");
        writer.write("hello World , 你好世界");
        writer.close();


        InputStreamReader reader = new InputStreamReader(new FileInputStream(file), "gbk");
        char[] contanier = new char[1024];
        int len = 0;
        StringBuilder sb = new StringBuilder();
        while ((len = reader.read(contanier)) != -1) {
            sb.append(contanier, 0, len);
        }
        System.out.println(sb.toString());
    }
}
